<template>
  <div>
    <div id="dog">
      <img
        src="https://scpic.chinaz.net/files/pic/pic9/202003/zzpic23514.jpg"
        alt=""
      />
      <p :style="{ backgroundColor: str }" @click="changeColor">
        这是一个孤独的狗
      </p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      str: "",
    };
  },
  methods: {
    changeColor() {
      this.str = `rgb(${Math.floor(Math.random() * 256)},${Math.ceil(
        Math.random() * 256
      )},${Math.ceil(Math.random() * 256)})`;
    },
  },
};
</script>

<style>
#dog {
  border: 1px solid #000;
  width: 300px;
  float: left;
}
#dog img {
  width: 100%;
}
p {
  text-align: center;
}
</style>